<template>
  <div class="content">
    <div class="info-box">
      <div class="top">
        <div class="left">
          <img :src="account.logo" mode="scaleToFill" />
          <p>{{evaluateForm.shopName}}</p>
        </div>
        <p>{{evaluateForm.evaluateDate}}</p>
      </div>
      <div class="cont">
        <div class="evaluate">{{evaluateForm.evaluate}}</div>
        <div class="img">
          <img :src="evaluateForm.evaluateImage" mode="scaleToFill" />
        </div>
      </div>
      <span>美观好看#好吃美味</span>
    </div>
    <div class="star-box">
      <div class="cont" v-for="(item,index) in rtarList" :key="index">
        <span>{{item.label}}</span>
        <i-rate :value="item.value" :disabled="true" class="rateClasee" />
        <p>{{item.value}}分</p>
      </div>
    </div>
    <div class="set-box">
      <textarea
        :disabled="!form.evaluateOver"
        class="input"
        v-model="form.evaluateAgain"
        :placeholder="form.evaluateOver === '0' ? '请输入回复' : '暂无评价'"
      />
      <div class="set-submit" v-if="form.evaluateOver === '0'">
        <div class="left">
          <i-radio
            value="通过"
            :checked="checkedPass"
            color="#677afe"
            @change="handlePassChange"
          ></i-radio>
          <i-radio
            value="置顶"
            color="#677afe"
            :checked="checkedTop"
            @change="handleTopChange"
          ></i-radio>
        </div>
        <button class="btn" @click="submitClick">确认回复</button>
      </div>
    </div>
  </div>
</template>

<script>
import { FIND_GOODS_STAR, SHOP_SUBMIT_EVALUATE } from '@/api'
import { getCurrentPageParams } from '@/utils'

export default {
  components: {},
  data () {
    return {
      form: {},
      checkedPass: false,
      checkedTop: false,
      star: {
        expressScore: '0',
        goodsScore: '0',
        multipleScore: '0',
        serviceScore: '0'
      }
    }
  },
  created () {},
  computed: {
    account () {
      return this.$cookie.get('account')
    },
    evaluateForm () {
      let obj = this.$cookie.get('evaluate-item')
      obj.evaluateDate = obj.evaluateDate.split(' ')[0]
      obj.shopName = this.nameReg(obj.shopName)
      return obj
    },
    rtarList () {
      return [
        {
          label: '综合评分',
          value: this.star.multipleScore
        },
        {
          label: '服务评分',
          value: this.star.serviceScore
        },
        {
          label: '物流评分',
          value: this.star.expressScore
        },
        {
          label: '商品评分',
          value: this.star.goodsScore
        }
      ]
    },
    evaluateState () {
      if (getCurrentPageParams('type') === 'find') {
        return false
      } else {
        return true
      }
    }
  },
  onShow () {
    this.init()
    this.findGoodsStar()
  },
  methods: {
    nameReg (val) {
      if (val && val.length) {
        let len = val.length - 1
        let xin = ''
        for (let i = 0; i < len; i++) {
          xin += '*'
        }
        return val.substr(0, 1) + xin
      } else {
        return '-'
      }
    },
    handlePassChange (e) {
      console.log(e)
      console.log(e.target)
      this.checkedPass = e.target.current
    },
    handleTopChange (e) {
      this.checkedTop = e.target.current
    },
    submitClick () {
      if (!this.form.evaluateAgain) {
        this.$toast('还未填写回复')
        return false
      }
      this.shopSubmitEvaluate()
    },
    init () {
      const vm = this
      vm.form = {}
      vm.checkedPass = false
      vm.checkedTop = false
      vm.star = {
        expressScore: '0',
        goodsScore: '0',
        multipleScore: '0',
        serviceScore: '0'
      }
    },
    /** api **/
    shopSubmitEvaluate () {
      const vm = this
      let params = {
        evaluateAgain: vm.form.evaluateAgain,
        goodsNo: vm.evaluateForm.goodsNo,
        orderNo: vm.evaluateForm.orderNo
      }
      if (vm.checkedPass) {
        params.checkState = '1'
      } else {
        params.checkState = '2'
      }
      if (vm.checkedTop) {
        params.checkState = '0'
      } else {
        params.checkState = '1'
      }
      SHOP_SUBMIT_EVALUATE(params)
        .then(r => {
          if (r.data.code === '0') {
            vm.$alert('设置回复成', '').then(() => {
              vm.$router.go(-1)
            })
          } else {
            vm.$toast(r.data.message)
          }
        })
        .catch(e => {
          console.info(e)
        })
    },
    findGoodsStar () {
      const vm = this
      FIND_GOODS_STAR(vm.evaluateForm.shopId, vm.evaluateForm.goodsNo)
        .then(r => {
          if (r.data.code === '0') {
            vm.star = r.data.data
          } else {
            vm.star = {
              expressScore: '0',
              goodsScore: '0',
              multipleScore: '0',
              serviceScore: '0'
            }
            vm.$toast(r.data.message)
          }
        })
        .catch(e => {
          console.info(e)
        })
    }
  }
}
</script>

<style lang="scss">
@import 'static/styles/color.scss';
.content {
  width: 100%;
  background: #f2f3f5;
  > .info-box {
    width: 100%;
    padding: 0 15px;
    background: #fff;
    > .top {
      height: 80px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      > .left {
        display: flex;
        align-items: center;
        > img {
          width: 35px;
          height: 35px;
          border-radius: 50px;
        }
        > p {
          font-size: 13px;
          margin-left: 5px;
        }
      }
      > p {
        font-size: 12px;
        color: #a4a4a4;
      }
    }
    > .cont {
      > .evaluate {
        font-size: 14px;
      }
      > .img {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        margin-top: 10px;
        > img {
          width: 145px;
          height: 145px;
          border-radius: 6px;
        }
      }
    }
    > span {
      height: 35px;
      line-height: 35px;
      font-size: 14px;
      color: #677afe;
    }
  }
  > .star-box {
    width: 100%;
    margin: 10px 0;
    padding: 0 15px;
    background: #fff;
    > div {
      height: 50px;
      display: flex;
      align-items: center;
      justify-content: center;
      > span {
        font-size: 13px;
        color: #a4a4a4;
      }
      > .rateClasee {
        margin: 0 15px 0 10px;
      }
      > p {
        font-size: 12px;
        color: #ffc556;
      }
    }
  }
  > .set-box {
    width: 100%;
    background: #fff;
    > .input {
      width: 100%;
      height: 120px;
      padding: 20px 15px 0;
    }
    > .set-submit {
      width: 100%;
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      > .left {
        display: flex;
        align-items: center;
      }
      > .btn {
        width: 95px;
        height: 40px;
        margin: 0;
        padding: 0;
        border: 0;
        border-radius: 0;
        background: #677afe;
        color: #fff;
        font-size: 14px;
        line-height: 40px;
      }
    }
  }
}
</style>
